package day4;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author oldliu
 * @since 1.0
 */
public class MapTest4 {
    public static void main(String[] args) {
        //字典
        Map<String,String> map=new HashMap<>();
        map.put("dog","狗");
        map.put("snake","蛇");
        map.put("python","蟒蛇");
        map.put("tiger","老虎");
        map.put("dog","小狗");
        map.put("none",null);
        //迭代
        //Map的定义略
        int size = map.size();
        System.out.println(size);
        Set<String> keys = map.keySet();//返回了所有的key集合
        Iterator<String> ir = keys.iterator();
        while (ir.hasNext()){//循环key
            String key = ir.next();
            String value=map.get(key);//通过key获得value
            System.out.println(key+"="+value);
        }
        System.out.println("-------------------------------------");
        Set<Map.Entry<String, String>> entries = map.entrySet();
         //增强for
        for(Map.Entry<String,String> f:entries){
            System.out.println(f.getKey()+",,,,"+f.getValue());
        }
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>");
        //Entry表示一个键值对
        //内部类
        Iterator<Map.Entry<String, String>> ir2 = entries.iterator();
        while (ir2.hasNext()){
            Map.Entry<String, String> kv = ir2.next();
            System.out.println(kv.getKey()+"-"+kv.getValue());
        }
    }
}
